package com.ctrip.ec.api.admin.controller.shipping;
import com.ctrip.ec.api.admin.model.query.QueryModel;
import com.ctrip.ec.dal.PagerSetting;
import com.ctrip.ec.api.admin.common.RequestContext;
import com.ctrip.ec.biz.dao.shipping.ShippingConfigDao;
import com.ctrip.ec.biz.entity.shipping.ShippingConfigEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;
@RestController
@RequestMapping("shippingConfig")
public class ShippingConfigController{
    @Autowired
    private ShippingConfigDao shippingConfig;

    @PostMapping("list")
    public List<ShippingConfigEntity> list(@RequestBody QueryModel model) throws  SQLException{
        PagerSetting setting = model.build();
        List<ShippingConfigEntity> list = shippingConfig.list(setting);
        RequestContext.setResponseHeaderCount(setting.getRecordCount());
        return list;
    }

    @GetMapping("detail/{id}")
    public  ShippingConfigEntity detail(@PathVariable Long id) throws SQLException {
        return shippingConfig.entity(id);
    }

    @PostMapping("save")
    public  Long save(@RequestBody ShippingConfigEntity entity) throws SQLException {
        shippingConfig.save(entity);
        return entity.getId();
    }

    @PostMapping("delete")
    public  void delete(@RequestBody List<Long> ids) throws SQLException {
        shippingConfig.delete(ids);
    }
    @PostMapping("erase")
    public void erase(@RequestBody List<Long> ids) throws  SQLException{
        shippingConfig.erase(ids);
    }

    @PostMapping("unerase")
    public  void unerase(@RequestBody List<Long> ids) throws  SQLException{
        shippingConfig.unerase(ids);
    }
}
